﻿Module Module1

    Sub Main()
        If My.Application.CommandLineArgs.Count <> 0 Then
            Dim strArg As String
            For intCounter As Integer = 0 To My.Application.CommandLineArgs.Count - 2
                strArg = My.Application.CommandLineArgs.Item(intCounter).ToLower
                If strArg.StartsWith("-") Or strArg.StartsWith("/") Then
                    strArg = strArg.Substring(1)
                End If
                Dim strEncodedURL As String = System.Web.HttpUtility.UrlEncode(My.Application.CommandLineArgs(My.Application.CommandLineArgs.Count - 1))
                Dim strTempString As String
                If strArg = "h" Or strArg = "help" Then
                    Console.WriteLine("MURLS_CMD 1.0.1 (c) 2009 Gregory Beauregard, aka: Gnintendo, Nintendo_G, WolfWolf")
                    Console.WriteLine("Usage: MURLS_CMD.exe [shortener domains/help] [URL]")
                    Console.WriteLine("Example: MURLS_CMD.exe bit.ly u.nu http://www.google.com")
                    Console.WriteLine("Note: It will always attempt to use the last argument as URL and will display all results in the order supplied")
                    Continue For
                End If
                If strArg = "u.nu" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://u.nu/unu-api-simple?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "u.nu")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: u.nu")
                    End Try
                    Continue For
                End If
                If strArg = "r.im" Then
                    Try
                        strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://r.im/api/index.cfm?long_url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadToEnd()
                        If strTempString.IndexOf("h") <> -1 Then
                            DisplayURL(strTempString.Substring(strTempString.IndexOf("h")), "r.im")
                        End If
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: r.im")
                    End Try
                    Continue For
                End If
                If strArg = "z.pe" Then
                    Try
                        strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://api.z.pe/new.txt?href=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine()
                        If strTempString.Substring(0, 5) <> "error" Then
                            DisplayURL("http://z.pe/" & strTempString.Substring(5), "z.pe")
                        End If
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: z.pe")
                    End Try
                    Continue For
                End If
                If strArg = "a.gd" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://a.gd/?module=ShortURL&file=Add&mode=API&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "a.gd")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: a.gd")
                    End Try
                    Continue For
                End If
                If strArg = "a.nf" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://a.nf/?module=ShortURL&file=Add&mode=API&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "a.nf")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: a.nf")
                    End Try
                    Continue For
                End If
                If strArg = "is.gd" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://is.gd/api.php?longurl=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "is.gd")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: is.gd")
                    End Try
                    Continue For
                End If
                If strArg = "kl.am" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://kl.am/api/shorten/?format=text&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "kl.am")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: kl.am")
                    End Try
                    Continue For
                End If
                If strArg = "ad.ag" Or strArg = "mobiletinyurl.com" Then
                    Try
                        DisplayURL("http://" & New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://mobiletinyurl.com/create/?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "ad.ag")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: ad.ag")
                    End Try
                    Continue For
                End If
                If strArg = "tr.im" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://api.tr.im/api/trim_simple?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "tr.im")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: tr.im")
                    End Try
                    Continue For
                End If
                If strArg = "bit.ly" Then
                    Try
                        Dim srStreamReader As New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://api.bit.ly/shorten?version=2.0.1&longUrl=" & strEncodedURL & "&login=gnintendo&apiKey=R_d9b6a87c77c3db06f32492f8d87e9b0c").GetResponse.GetResponseStream)
                        For intCounter2 As Integer = 1 To 8
                            If intCounter2 <> 8 Then
                                srStreamReader.ReadLine()
                            Else
                                strTempString = srStreamReader.ReadLine().Substring(25)
                                strTempString = strTempString.Substring(0, strTempString.LastIndexOf(",") - 1)
                                DisplayURL(strTempString, "bit.ly")
                            End If
                        Next
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: bit.ly")
                    End Try
                    Continue For
                End If
                If strArg = "cli.gs" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://cli.gs/api/v1/cligs/create?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "cli.gs")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: cli.gs")
                    End Try
                    Continue For
                End If
                If strArg = "vtc.es" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://vtc.es/create.php?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "vtc.es")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: vtc.es")
                    End Try
                    Continue For
                End If
                If strArg = "krz.ch" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://krz.ch/?module=ShortURL&file=Add&mode=API&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "krz.ch")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: krz.ch")
                    End Try
                    Continue For
                End If
                If strArg = "sai.ly" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://www.sai.ly/new.txt?href=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "sai.ly")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: sai.ly")
                    End Try
                    Continue For
                End If
                If strArg = "pic.gd" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://pic.gd/?module=ShortURL&file=Add&mode=API&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "pic.gd")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: pic.gd")
                    End Try
                    Continue For
                End If
                If strArg = "buk.me" Then
                    Try
                        strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://buk.me/api.php?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine()
                        DisplayURL(strTempString.Substring(0, strTempString.IndexOf("<")), "buk.me")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: buk.me")
                    End Try
                    Continue For
                End If
                If strArg = "xrl.us" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://metamark.net/api/rest/simple?long_url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "xrl.us")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: xrl.us")
                    End Try
                    Continue For
                End If
                If strArg = "fwd4.me" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://api.fwd4.me/?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "fwd4.me")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: fwd4.me")
                    End Try
                    Continue For
                End If
                If strArg = "idek.net" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://idek.net/c.php?idek-api=true&idek-ref=your_app&idek-anchor=anchortag&idek-url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "idek.net")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: idek.net")
                    End Try
                    Continue For
                End If
                If strArg = "short.to" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://short.to/s.txt?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "short.to")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: short.to")
                    End Try
                    Continue For
                End If
                If strArg = "chilp.it" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://chilp.it/api.php?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "chilp.it")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: chilp.it")
                    End Try
                    Continue For
                End If
                If strArg = "kissa.be" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://kissa.be/api/shortener/url?content=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "kissa.be")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: kissa.be")
                    End Try
                    Continue For
                End If
                If strArg = "snurl.com" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://snurl.com/site/snip?r=simple&link=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "snurl.com")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: snurl.com")
                    End Try
                    Continue For
                End If
                If strArg = "unfake.it" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://unfake.it/?a=api&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "unfake.it")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: unfake.it")
                    End Try
                    Continue For
                End If
                If strArg = "abbrr.com" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://api.abbrr.com/api.php?out=link&url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "abbrr.com")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: abbrr.com")
                    End Try
                    Continue For
                End If
                If strArg = "tinyurl.com" Then
                    Try
                        DisplayURL(New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://tinyurl.com/api-create.php?url=" & strEncodedURL).GetResponse().GetResponseStream()).ReadLine(), "tinyurl.com")
                    Catch ThrewError As Exception
                        Console.WriteLine("Error: tinyurl.com")
                    End Try
                    Continue For
                End If
                Console.WriteLine("Error: " & strArg & ": Shortener not supported")
            Next
            strArg = My.Application.CommandLineArgs.Item(My.Application.CommandLineArgs.Count - 1).ToLower
            If strArg.StartsWith("-") Or strArg.StartsWith("/") Then
                strArg = strArg.Substring(1)
            End If
            If strArg = "h" Or strArg = "help" Then
                Console.WriteLine("MURLS_CMD 1.0.1 (c) 2009 Gregory Beauregard, aka: Gnintendo, Nintendo_G, WolfWolf")
                Console.WriteLine("Usage: MURLS_CMD.exe [shortener domains/help] [URL]")
                Console.WriteLine("Example: MURLS_CMD.exe bit.ly u.nu http://www.google.com")
                Console.WriteLine("Note: It will always attempt to use the last argument as URL and will display all results in the order supplied")
            End If
        Else
            Console.WriteLine("MURLS_CMD 1.0.1 (c) 2009 Gregory Beauregard, aka: Gnintendo, Nintendo_G, WolfWolf")
            Console.WriteLine("Usage: MURLS_CMD.exe [shortener domains/help] [URL]")
            Console.WriteLine("Example: MURLS_CMD.exe bit.ly u.nu http://www.google.com")
            Console.WriteLine("Note: It will always attempt to use the last argument as URL and will display all results in the order supplied")
        End If
    End Sub

    Private Sub DisplayURL(ByVal strURL As String, ByVal strWebsite As String)
        If Len(strURL) <> 0 Then
            If strURL.StartsWith("http://") = True And strURL.Contains("<") = False Then
                Console.WriteLine(strURL)
            Else
                Console.WriteLine("Error: " & strWebsite)
            End If
        Else
            Console.WriteLine("Error: " & strWebsite)
        End If
    End Sub

End Module
